extends Control

signal start_game() #定义信号 开始游戏

#节点加载
@onready var round_1_name = $AllRound/Round1/RoundName
@onready var round_2_name = $AllRound/Round2/RoundName
@onready var round_3_name = $AllRound/Round3/RoundName
@onready var round_4_name = $AllRound/Round4/RoundName
@onready var round_5_name = $AllRound/Round5/RoundName

@onready var round_1_score = $AllRound/Round1/RoundScore
@onready var round_2_score = $AllRound/Round2/RoundScore
@onready var round_3_score = $AllRound/Round3/RoundScore
@onready var round_4_score = $AllRound/Round4/RoundScore
@onready var round_5_score = $AllRound/Round5/RoundScore

@onready var start_1_btn = $AllRound/Round1/StartRound
@onready var start_2_btn = $AllRound/Round2/StartRound
@onready var start_3_btn = $AllRound/Round3/StartRound
@onready var start_4_btn = $AllRound/Round4/StartRound
@onready var start_5_btn = $AllRound/Round5/StartRound

func _ready() -> void:
	start_1_btn.connect("pressed", Callable(self, "_pressToPlay"))
	start_2_btn.connect("pressed", Callable(self, "_pressToPlay"))
	start_3_btn.connect("pressed", Callable(self, "_pressToPlay"))
	start_4_btn.connect("pressed", Callable(self, "_pressToPlay"))
	start_5_btn.connect("pressed", Callable(self, "_pressToPlay"))
	showRounds()

#展示回合
func showRounds():
	var currentBigRound = RoundDetail.currentBigRound
	var currentSmallRound = RoundDetail.currentSmallRound
	for i in range(1, 6):
		var roundId = str(currentBigRound) + "-" + str(i)
		var round = getRoundById(roundId)
		match i:
			1:
				round_1_name.text = round.roundName
				round_1_score.text = "要求分数：" + str(round.targetScore)
			2:
				round_2_name.text = round.roundName
				round_2_score.text = "要求分数：" + str(round.targetScore)
			3:
				round_3_name.text = round.roundName
				round_3_score.text = "要求分数：" + str(round.targetScore)
			4:
				round_4_name.text = round.roundName
				round_4_score.text = "要求分数：" + str(round.targetScore)
			5:
				round_5_name.text = round.roundName
				round_5_score.text = "要求分数：" + str(round.targetScore)

	match currentSmallRound:
		1:
			start_1_btn.visible = true
		2:
			start_2_btn.visible = true
		3:
			start_3_btn.visible = true
		4:
			start_4_btn.visible = true
		5:
			start_5_btn.visible = true

#通关id获取回合
func getRoundById(roundId):
	for item in RoundDetail.rounds:
		if item["roundId"] == roundId:
			return item  # 返回匹配的元素

#点击按钮到play场景
func _pressToPlay():
	emit_signal("start_game")  # 发送信号
